unit UnitNuevoPaciente;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  sqldb, UnitMainForm;

type

  { TFormNuevoPaciente }

  TFormNuevoPaciente = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    SQLQuery1: TSQLQuery;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    nuevopte_codigo : string;
    nuevopte_nombre : string;
    nuevopte_dni : string;
  end; 

var
  FormNuevoPaciente: TFormNuevoPaciente;

implementation

{$R *.lfm}

{ TFormNuevoPaciente }

procedure TFormNuevoPaciente.FormShow(Sender: TObject);
begin
  nuevopte_codigo := '';
  nuevopte_nombre := '';
  nuevopte_dni := '';
  Edit1.Text := '';
  Edit2.Text := '';

  Edit1.SetFocus;
end;

procedure TFormNuevoPaciente.Button2Click(Sender: TObject);
begin
  Close();
end;

procedure TFormNuevoPaciente.Button1Click(Sender: TObject);
begin
  if (Edit1.Text <> '') and (Edit2.Text <> '') then
  begin
    Edit1.text := uppercase(Edit1.Text);

    SQLQuery1.SQL.Text := 'insert into paciente(pte_nombre, pte_dni) values(''' + Edit1.Text
      + ''', ''' + Edit2.Text + ''')';

    SQLQuery1.ExecSQL;

    SQLQuery1.SQL.Text := 'select pte_cdg from paciente where pte_dni = ' + Edit2.Text;

    SQLQuery1.Open;

    while not SQLQuery1.EOF do
    begin
      nuevopte_codigo := SQLQuery1.Fields[0].AsString;
      SQLQuery1.Next;
    end;

    SQLQuery1.Close;

    nuevopte_nombre := Edit1.Text;

    nuevopte_dni := Edit2.Text;

    ShowMessage('Alta Exitosa');

    Close();
  end;
end;

end.

